'Imports DotNetNuke.Modules.UserDefinedTable

Module Module1

    Sub Main()
        Main(Environment.GetCommandLineArgs)
    End Sub

    Private Sub Main(ByVal args() As String)
        Console.WriteLine("Csv2UdtImport V0.2")
        Console.WriteLine("Copyright (c) 2008 Stefan Cullmann")

        If args.Length = 1 OrElse args.Length > 3 Then
            Console.WriteLine()
            Console.WriteLine("Usage: Csv2UdtImport filename [noheadlines]")
        Else
            Dim filename As String = args(1)
            Dim headlines As Boolean = Not (args.Length = 3 AndAlso args(2) = "noheadlines")
            Dim ds As DataSet = CsvReader.ImportToUDTDataSet(filename, headlines, "ImportFromCsv")
            Dim outputfilename As String = String.Format("content.DNNUserDefinedTable.{0}.xml", System.IO.Path.GetFileNameWithoutExtension(filename))
            Using tw As IO.TextWriter = New IO.StreamWriter(outputfilename, False, System.Text.Encoding.UTF8)

                tw.WriteLine("<?xml version=""1.0"" encoding=""utf-8"" ?>")
                tw.WriteLine("<content type=""DNNUserDefinedTable"" version=""3.0.0"">")
                ds.WriteXml(tw)
                tw.WriteLine("</content>")
            End Using

            Console.WriteLine("Udt import file saved to {0}", outputfilename)
        End If
    End Sub


End Module
